import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'

/**
 * Note: sub-menu only appear when route children.length >= 1
 * Detail see: https://panjiachen.github.io/vue-element-admin-site/guide/essentials/router-and-nav.html
 *
 * hidden: true                   if set true, item will not show in the sidebar(default is false)
 * alwaysShow: true               if set true, will always show the root menu
 *                                if not set alwaysShow, when item has more than one children route,
 *                                it will becomes nested mode, otherwise not show the root menu
 * redirect: noRedirect           if set noRedirect will no redirect in the breadcrumb
 * name:'router-name'             the name is used by <keep-alive> (must set!!!)
 * meta : {
    title: 'title'               the name show in sidebar and breadcrumb (recommend set)
    icon: 'svg-name'/'el-icon-x' the icon show in the sidebar
    breadcrumb: false            if set false, the item will hidden in breadcrumb(default is true)
    activeMenu: '/example/list'  if set path, the sidebar will highlight the path you set
  }
 */

/**
 * routes
 * 所有路由配置，包括所有页面路由，不再区分常量路由和异步路由
 */
export const constantRoutes = [
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },

  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  },

  {    
    path: '/',
    component: Layout,
    redirect: '/home',
    children: [
      {
        path: 'home',
        name: 'Home',
        component: () => import('@/views/home/index'),
        meta: {
          title: '消防巡检系统首页',
          icon: 'el-icon-s-home',
          affix: true
        }
      }
    ]
  },

  // 系统管理模块
  {
    path: '/system',
    component: Layout,
    redirect: '/system/user',
    name: 'System',
    meta: {
      title: '系统管理',
      icon: 'el-icon-setting'
    },
    children: [
      {
        path: 'user',
        name: 'User',
        component: () => import('@/views/system/user/index'),
        meta: {
          title: '用户管理',
          icon: 'el-icon-user'
        }
      },
      {
        path: 'role',
        name: 'Role',
        component: () => import('@/views/system/role/index'),
        meta: {
          title: '角色管理',
          icon: 'el-icon-s-custom'
        }
      },
      {
        path: 'menu',
        name: 'Menu',
        component: () => import('@/views/system/menu/index'),
        meta: {
          title: '菜单管理',
          icon: 'el-icon-menu'
        }
      },
      {
        path: 'dept',
        name: 'Dept',
        component: () => import('@/views/system/dept/index'),
        meta: {
          title: '部门管理',
          icon: 'el-icon-s-unfold'
        }
      },
      {
        path: 'dict',
        name: 'Dict',
        component: () => import('@/views/system/dict/index'),
        meta: {
          title: '字典管理',
          icon: 'el-icon-s-order'
        }
      },
      {
        path: 'dict-detail',
        name: 'DictDetail',
        component: () => import('@/views/system/dict-detail/index'),
        meta: {
          title: '字典详情',
          icon: 'el-icon-document'
        },
        hidden: true
      },
      {
        path: 'operation-log',
        name: 'OperationLog',
        component: () => import('@/views/system/operation-log/index'),
        meta: {
          title: '操作日志',
          icon: 'el-icon-document-checked'
        }
      },
      {
        path: 'performance-log',
        name: 'PerformanceLog',
        component: () => import('@/views/system/performance-log/index'),
        meta: {
          title: '性能日志',
          icon: 'el-icon-s-data'
        }
      },
      {
        path: 'announcement',
        name: 'Announcement',
        component: () => import('@/views/system/announcement/index'),
        meta: {
          title: '系统公告',
          icon: 'el-icon-bell'
        }
      },
      {
        path: 'config',
        name: 'Config',
        component: () => import('@/views/system/config/index'),
        meta: {
          title: '系统配置',
          icon: 'el-icon-setting'
        }
      },
      {
        path: 'backup',
        name: 'Backup',
        component: () => import('@/views/system/backup/index'),
        meta: {
          title: '系统备份',
          icon: 'el-icon-document-copy'
        }
      },
      {
        path: 'operation-log-analysis',
        name: 'OperationLogAnalysis',
        component: () => import('@/views/system/operation-log-analysis/index'),
        meta: {
          title: '日志分析',
          icon: 'el-icon-data-line'
        }
      }
    ]
  },

  // 设备管理模块
  {
    path: '/device',
    component: Layout,
    redirect: '/device/list',
    name: 'Device',
    meta: {
      title: '设备管理',
      icon: 'el-icon-monitor'
    },
    children: [
      {
        path: 'list',
        name: 'DeviceList',
        component: () => import('@/views/device/list/index'),
        meta: {
          title: '设备列表',
          icon: 'el-icon-document'
        }
      }
    ]
  },

  // 巡检任务模块
  {
    path: '/inspection',
    component: Layout,
    redirect: '/inspection/task',
    name: 'Inspection',
    meta: {
      title: '巡检管理',
      icon: 'el-icon-check'
    },
    children: [
      {  
        path: 'task',
        name: 'InspectionTask',
        component: () => import('@/views/inspection/task/index'),
        meta: {  
          title: '巡检任务',
          icon: 'el-icon-date'
        }
      },
      {  
        path: 'task/detail/:id',
        name: 'InspectionTaskDetail',
        component: () => import('@/views/inspection/task/detail/index'),
        meta: {  
          title: '任务详情',
          activeMenu: '/inspection/task'
        },
        hidden: true
      },
      {
        path: 'record',
        name: 'InspectionRecord',
        component: () => import('@/views/inspection/record/index'),
        meta: {
          title: '巡检记录',
          icon: 'el-icon-document-checked'
        }
      },
      {
        path: 'list',
        name: 'InspectionList',
        component: () => import('@/views/inspection/list/index'),
        meta: {
          title: '巡检列表',
          icon: 'el-icon-s-order'
        }
      }
    ]
  },

  // 维修管理模块
  {
    path: '/maintenance',
    component: Layout,
    redirect: '/maintenance/request',
    name: 'Maintenance',
    meta: {
      title: '维修管理',
      icon: 'el-icon-edit-outline'
    },
    children: [
      {
        path: 'request',
        name: 'RepairRequest',
        component: () => import('@/views/maintenance/request/index'),
        meta: {
          title: '维修申请',
          icon: 'el-icon-plus'
        }
      },
      {
        path: 'assign',
        name: 'MaintenanceAssign',
        component: () => import('@/views/maintenance/assign/index'),
        meta: {
          title: '任务指派',
          icon: 'el-icon-s-promotion'
        }
      },
  
      {
        path: 'complete',
        name: 'MaintenanceComplete',
        component: () => import('@/views/maintenance/complete/index'),
        meta: {
          title: '维修完成',
          icon: 'el-icon-check'
        }
      }
    ]
  },

  // 统计模块
  {
    path: '/statistics',
    component: Layout,
    redirect: '/statistics/device',
    name: 'Statistics',
    meta: {
      title: '数据统计',
      icon: 'el-icon-data-analysis'
    },
    children: [
      {
        path: 'device',
        name: 'DeviceStatistics',
        component: () => import('@/views/statistics/device/index'),
        meta: {
          title: '设备统计',
          icon: 'el-icon-pie-chart'
        }
      },
      {
        path: 'task',
        name: 'TaskStatistics',
        component: () => import('@/views/statistics/task/index'),
        meta: {
          title: '任务统计',
          icon: 'el-icon-s-data'
        }
      },
      {
        path: 'repair',
        name: 'RepairStatistics',
        component: () => import('@/views/statistics/repair/index'),
        meta: {
          title: '维修统计',
          icon: 'el-icon-s-data'
        }
      }
    ]
  },

  // 404 page must be placed at the end !!!
  { path: '*', redirect: '/404', hidden: true }
]

const createRouter = () => new Router({
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes,
  mode: 'history'
})

const router = createRouter()

export default router
